package com.example.demo.controller.system;

import com.example.demo.annoation.Log;
import com.example.demo.bean.AjaxRes;
import com.example.demo.bean.sysnotice.SysNoticeDO;
import com.example.demo.controller.BaseAdminController;
import com.example.demo.enums.BusinessType;
import com.example.demo.service.ISysNoticeService;
import com.example.demo.dto.sysnotice.SysNoticePageReqVO;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RequestMapping(value = "/system/sys_notice")
@RestController
public class SysNoticeController extends BaseAdminController {

    @Resource
    private ISysNoticeService sysNoticeService;

    @GetMapping("/list")
    public AjaxRes list(SysNoticePageReqVO sysNoticePageReqVO) {
        return AjaxRes.success(sysNoticeService.list(sysNoticePageReqVO));
    }

    @PostMapping("/insert")
    @Log(title = "新增系统通知", businessType = BusinessType.INSERT)
    public AjaxRes insert(@RequestBody SysNoticeDO sysNoticeDO) {
        return toAjax(sysNoticeService.addSysNotice(sysNoticeDO));
    }

    @DeleteMapping("/delete/{noticeId}")
    @Log(title = "删除系统通知", businessType = BusinessType.DELETE)
    public AjaxRes delete(@PathVariable("noticeId") Long noticeId) {
        return toAjax(sysNoticeService.deleteSysNotice(new SysNoticeDO().setNoticeId(noticeId)));
    }

    @PutMapping("/update")
    @Log(title = "更新系统通知", businessType = BusinessType.UPDATE)
    public AjaxRes update(@RequestBody SysNoticeDO sysNoticeDO) {
        return toAjax(sysNoticeService.updateSysNotice(sysNoticeDO));
    }

    @GetMapping("/{noticeId}")
    public AjaxRes query(@PathVariable("noticeId") Long noticeId) {
        return AjaxRes.success(sysNoticeService.getSysNotice(new SysNoticeDO().setNoticeId(noticeId)));
    }
}
